<?php

namespace App\Admin\Controllers;

use App\Models\TcmTeaDetail;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TcmTeaDetailController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TcmTeaDetail(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('pinyin');
            $grid->column('picture')->image('',50,50);
            //$grid->column('shareImg');
            $grid->column('teaCategory');
            $grid->column('natures');
            $grid->column('flavors');
            //$grid->column('pickSeason');
            //$grid->column('meridian');
            //$grid->column('processing');
            //$grid->column('drugEffects');
            //$grid->column('healthBenefits');
            //$grid->column('originImg');
            $grid->column('classification');
            //$grid->column('history');
            //$grid->column('story');
            //$grid->column('poetry');
            //$grid->column('created_at');
            //$grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TcmTeaDetail(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('pinyin');
            $show->field('picture')->image('',100,100);
            $show->field('shareImg')->image('',100,100);
            $show->field('teaCategory');
            $show->field('natures')->json();
            $show->field('flavors')->json();
            $show->field('pickSeason');
            $show->field('meridian');
            $show->field('processing');
            $show->field('drugEffects');
            $show->field('healthBenefits');
            $show->field('originImg')->image('',100,100);
            $show->field('classification');
            $show->field('history');
            $show->field('story');
            $show->field('poetry');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TcmTeaDetail(), function (Form $form) {
			$form->tab('基本信息', function (Form $form) {
				$form->display('id');
				$form->text('name');
				$form->text('pinyin');
				$form->image('picture')->uniqueName()->autoUpload()->saveFullUrl();
				$form->image('shareImg')->uniqueName()->autoUpload()->saveFullUrl();
				$form->text('pickSeason');
				$form->text('teaCategory');
				$form->text('classification');
				$form->list('natures')->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
				$form->list('flavors')->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
				
			});
			
			
            $form->tab('性味归经', function (Form $form) {
				$form->array('meridian','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->image('images','图片')->uniqueName()->autoUpload()->saveFullUrl();
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('炮制方法', function (Form $form) {
				 $form->editor('processing');
			});
			
			$form->tab('药效', function (Form $form) {
				 $form->array('drugEffects','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('养生保健功效', function (Form $form) {
				 $form->editor('healthBenefits');
			});
			$form->tab('产地图片', function (Form $form) {
				 $form->image('originImg')->uniqueName()->autoUpload()->saveFullUrl();
			});
			
            
            $form->tab('溯源', function (Form $form) {
				$form->array('history','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('轶事', function (Form $form) {
				$form->array('story','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('诗词', function (Form $form) {
				$form->array('poetry','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
